//
//  MZColorDemoViewController.m
//  MZBaseDemo
//
//  Created by Chris Yang on 2016/12/2.
//  Copyright © 2016年 Chris Yang. All rights reserved.
//

#import <YYCategories.h>

#import "UIColor+MZBase.h"
#import "MZColorDemoView.h"

#import "MZColorDemoViewController.h"

@interface MZColorDemoViewController ()
<MZColorDemoViewDelegate>

@property (nonatomic, strong) MZColorDemoView *demoView;

@end

@implementation MZColorDemoViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self selfConfig];
}

- (void)selfConfig {
    
    NSArray *prefixArray = @[
                             @"RGBColor",
                             @"RGBAlphaColor",
                             @"RGBAColor",
                             @"RandomColor",
                             @"RandomAlphaColor",
                             ];
    
    _demoView = [[MZColorDemoView alloc] init];
    [_demoView resetWithTitlePrefixArray:prefixArray];
    [_demoView setDelegate:self];
    [self.view addSubview:_demoView];
    [_demoView setFrame:self.view.bounds];
}

#pragma mark - MZColorDemoViewDelegate

- (void)colorView:(MZColorDemoView *)view colorButtonClickedAtIndex:(NSInteger)index {
    
    uint32_t tmpValue = 0;
    float tmpAlpha = 0;
    
    UIColor *tmpColor = nil;
    NSString *tmpTitle = @"";
    
    if (0 == index) {
        
        tmpValue = rand() % 0xffffff;
        tmpColor = [UIColor colorWithRGB:tmpValue];
        tmpTitle = [NSString stringWithFormat:@"0x%x", tmpValue];
        
    } else if (1 == index) {
        tmpValue = rand() % 0xffffff;
        tmpAlpha = (rand() % 100) / 100.0;
        tmpColor = [UIColor colorWithRGB:tmpValue alpha:tmpAlpha];
        tmpTitle = [NSString stringWithFormat:@"0x%x(%.2f)", tmpValue, tmpAlpha];
        
    } else if (2 == index) {
        
        tmpValue = rand() % 0xffffffff;
        tmpColor = [UIColor colorWithRGB:tmpValue];
        tmpTitle = [NSString stringWithFormat:@"0x%x", tmpValue];
        
    } else if (3 == index) {
        
        tmpColor = [UIColor mzRandomColor];
        tmpValue = [tmpColor rgbValue];
        tmpTitle = [NSString stringWithFormat:@"0x%x", tmpValue];

    } else if (4 == index) {

        tmpAlpha = (rand() % 100) / 100.0;
        tmpColor = [UIColor mzRandomColorWithAlpha:tmpAlpha];
        tmpValue = [tmpColor rgbaValue];
        tmpTitle = [NSString stringWithFormat:@"0x%x", tmpValue];
    }
    
    [view setButtonTitle:tmpTitle color:tmpColor atIndex:index];
}

@end
















